//
//  DBBaseTabBarController.swift
//  DBCA
//
//  Created by mugua on 2024/7/1.
//

import Foundation
import UIKit

class DBBaseTabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupChildViewControllers()
        
        if #available(iOS 13.0, *) {
            let appearance = UITabBarAppearance()
            appearance.configureWithOpaqueBackground()
            appearance.backgroundImage = UIImage()
            appearance.backgroundColor = UIColor.white
            appearance.shadowImage = UIImage()
            appearance.shadowColor = nil
            appearance.backgroundEffect = nil
            if #available(iOS 15.0, *) {
                self.tabBar.scrollEdgeAppearance = appearance
            }
            self.tabBar.standardAppearance = appearance
        } else {
            self.tabBar.backgroundColor = UIColor.white
            self.tabBar.backgroundImage = UIImage()
            self.tabBar.shadowImage = UIImage()
        }
        
        self.tabBar.isTranslucent = true
    }
    
    func setupChildViewControllers() {
        setupOneChildViewController(childVC: DBHomeViewController(), image: "tab_home_unselected", selectedImage: "tab_home_selected")
        setupOneChildViewController(childVC: DBOrderViewController(), image: "tab_order_unselected", selectedImage: "tab_order_selected")
        setupOneChildViewController(childVC: DBMineViewController(), image: "tab_mine_unselected", selectedImage: "tab_mine_selected")
    }
    
    fileprivate func setupOneChildViewController(childVC: UIViewController, image: String, selectedImage: String) {
        childVC.tabBarItem.image = UIImage(named: image)?.withRenderingMode(.alwaysOriginal)
        childVC.tabBarItem.selectedImage = UIImage(named: selectedImage)?.withRenderingMode(.alwaysOriginal)
        childVC.tabBarItem.imageInsets = UIEdgeInsets(top: 3, left: 0, bottom: -3, right: 0)
        let nav = DBBaseNavigationController.init(rootViewController: childVC)
        self.addChild(nav)
    }
}



